_realname=scopehal-apps
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=ci
pkgrel=1
pkgdesc="scopehal-apps: applications for libscopehal (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url="https://github.com/glscopeclient/scopehal-apps"
license=('BSD-3-Clause')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-glm"
  "${MINGW_PACKAGE_PREFIX}-libsigc++"
  "${MINGW_PACKAGE_PREFIX}-cairomm"
  "${MINGW_PACKAGE_PREFIX}-yaml-cpp"
  "${MINGW_PACKAGE_PREFIX}-glew"
  "${MINGW_PACKAGE_PREFIX}-ffts"
  "${MINGW_PACKAGE_PREFIX}-vulkan-loader"
  "${MINGW_PACKAGE_PREFIX}-glfw"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
)

pkgver() {
  cd "${srcdir}"/../..
  echo '0.0.0.r'"$(git rev-list --count HEAD)"'.g'"$(git describe --all --long | sed 's/^.*-g\(.*\)/\1/')"
}

build() {
  cd "${srcdir}"/../..

  mkdir -p build
  cd build

  CXXFLAGS+=" -Wno-format" \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=Debug \
    -DWIXPATH="/c/Program Files (x86)/WiX Toolset v3.11/bin" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DBUILD_TESTING=OFF \
    ../

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}"/../../build
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install

  _licenses="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${_licenses}"
  install -m 644 "${srcdir}"/../../LICENSE "${_licenses}"
}
